<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>管理系统</h2>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" maxlength="3" lay-verify="required" placeholder="操作员编号"
          class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" maxlength="6" lay-verify="required" placeholder="密码"
          class="layui-input">
      </div>

      <div class="layui-form-item">
        <!-- <label class="layui-form-label">滑动验证</label> -->
        <div class="layui-input-block" style="margin-left: 0px;">
          <div id="slider"></div>
        </div>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登录</button>
      </div>

    </div>
  </div>

  <div class="layui-trans layadmin-user-login-footer">


  </div>


</div>
<style>
  #canvas {
    float: right;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
  }
</style>
<script>
  var show_num = [];
  var slider;
  history.pushState(null, null, document.URL);
  window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
  });




  function ResetSlider() {
    slider.reset();
  }

  layui.use(['admin', 'form', 'user', 'sliderVerify'], function () {
    var $ = layui.$,
      setter = layui.setter,
      admin = layui.admin,
      form = layui.form,
      router = layui.router(),
      search = router.search,
      sliderVerify = layui.sliderVerify;
    slider = sliderVerify.render({
      elem: '#slider',
      onOk: function () {
        let username = $("#LAY-user-login-username").val();
        if (username == null || username == '' || username == "undefined") {
          ResetSlider();
          layer.msg("请输入用户名!");
          return;
        }
        let password = $("#LAY-user-login-password").val();
        if (password == null || password == '' || password == "undefined") {
          ResetSlider();
          layer.msg("请输入密码!");
        }
      }
    });

    form.render();

    //提交
    form.on('submit(LAY-user-login-submit)', function (obj) {
      var field = obj.field;
      var l_Data = {
        "LoginName": field.username,
        "LoginSecret": field.password
      };

      var l_ResultData;

      var l_SearchJson = JSON.stringify(l_Data);
      $.ajax({
        url: layui.setter.url + "/LoginController/DMSOilDepot_login",
        type: 'post',
        dataType: 'json',
        contentType: 'application/json',
        data: l_SearchJson,
        async: false,
        success: function (data) {
          l_ResultData = data;
        }
      });
      if (l_ResultData != null) {
        if (l_ResultData.Result == "0") {
          //请求成功后，写入 access_token
          layui.data(setter.tableName, {
            key: setter.request.tokenName,
            value: '000000'
          });
          sessionStorage.setItem('FindOil_OperatorInfo', JSON.stringify(l_ResultData.Data));
          sessionStorage.setItem('FindOil_OperatorNo', JSON.stringify(l_ResultData.Data.operatorNo));
          sessionStorage.setItem('FindOil_OperatorName', "管理");
          sessionStorage.setItem('FindOil_RoleID', JSON.stringify(l_ResultData.Data.roleID));
          layer.msg('登入成功', {
            offset: '15px',
            icon: 1,
            time: 1000
          }, function () {
            window.location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/';
          });
        } else {
          layer.msg(l_ResultData.Msg);
        }
      } else {
        layer.msg("请求出错");
      }

    });

  });
</script>